//
//  THJWebviewVC.m
//  THJXHW
//
//  Created by 河南德艺 on 17/4/10.
//  Copyright © 2017年 河南德艺. All rights reserved.
//

#import "THJWebviewVC.h"
#import <WebKit/WebKit.h>


@interface THJWebviewVC ()<WKNavigationDelegate,UIWebViewDelegate>
{
    
}
@end

@implementation THJWebviewVC
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setStateBarColor:[UIColor whiteColor]];
    self.tabBarController.tabBar.hidden = YES;      
//     [MobClick beginLogPageView:@"资讯详情page"];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
//    [MobClick endLogPageView:@"资讯详情page"];
}
- (void)viewDidLoad{
   
    [super viewDidLoad];
    if(![self.title isEqual:@"物流轨迹"]){
        [self setRightNavBtn];
        self.title = @"资讯详情";
    }
    if (self.IsComeFromPush) {
        [self setUpNav];
    }
    self.view.backgroundColor = SingleColor(whiteColor);
//    [THJNetWork getNetDataFromUrl:self.detailUrl callback:^(NSDictionary* receiveData, NSError *error) {
//        NSLog(@"%@",receiveData);
//        WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
//       
//        //[webView loadHTMLString:receiveData[@"list"][@"content"] baseURL:nil];
//        NSString * str =  [NSString stringWithFormat:@"<html> \n"
//         "<head> \n"
//         "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no\" />"
//         "<style type=\"text/css\"> \n"
//         "body {font-family: \"%@\"; font-size: %@; color: %@;}\n"
//         "</style> \n"
//         "</head> \n"
//         "<body>%@</body> \n"
//         "</html>", @"宋体", @"17",@"black",receiveData[@"list"][@"content"]] ;
//         [webView loadHTMLString:str baseURL:nil];
//        webView.scrollView.bounces = NO;
//        webView.scrollView.showsVerticalScrollIndicator = NO;
//        webView.scrollView.showsHorizontalScrollIndicator = NO;
//        [self.view addSubview:webView];
//    }];
   
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight+44)];
    webView.backgroundColor = SingleColor(clearColor);
    NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:self.detailUrl]];
    //webView.navigationDelegate = self;
    webView.delegate = self;
    //webView.detectsPhoneNumbers = NO;
    webView.scrollView.bounces = NO;
    webView.scrollView.showsVerticalScrollIndicator = NO;
    webView.scrollView.showsHorizontalScrollIndicator = NO;
    [webView loadRequest:request];
    webView.opaque = NO;
    [self.view addSubview:webView];
    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    [self setGoBackBtn];
}

-(void)webViewDidFinishLoad:(UIWebView *)webView{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    NSString *str =
    @"var arr = document.getElementsByTagName('a');"
    "for(var i=0;i <arr.length;i++){"
    "arr[i].setAttribute(\"href\",\"#\");"
    "arr[arr.length-1].remove();"
    "}";
    [webView stringByEvaluatingJavaScriptFromString:str];
}
-(void)shareWithContent:(NSString*)content{
    NSLog(@"--%@",self.titleStr);
    [self shareWithContent:self.titleStr Title:self.titleStr Url:self.detailUrl];
}
@end
